//初始化
mui.init();
var mask = mui.createMask(); //遮罩层
//获取本地储存数据
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var is_realname, pay_password, description;
var status = 0; //修改手机号审核状态
//返回user页面
$(document).on('tap', '.go_user', function() {
	window.top.location.href = "../my/silver_list.html";
})

//document.getElementById("bank_card_add").addEventListener("tap", function() {
//	mui.openWindow({
//		url: '../my/silver_center.html',
//		createNew: true,
//	});
//});
//
//document.getElementById("advance_payment_detail").addEventListener("tap", function() {
//	mui.openWindow({
//		url: '../my/silver_record.html',
//		createNew: true,
//	});
//});

function formatTime (value){
  var d = new Date(value*1000);
  var year = d.getFullYear();
  var month = d.getMonth() + 1;
  var day = d.getDate();
  var hour = d.getHours();
  var minutes = d.getMinutes();
  var seconds = d.getSeconds();
	month < 10 ? (month = "0" + month) : month;
	day < 10 ? (day = "0" + day) : day;
	hour < 10 ? (hour = "0" + hour) : hour;
	minutes < 10 ? (minutes = "0" + minutes) : minutes;
	seconds < 10 ? (seconds = "0" + seconds) : seconds;
    return year+ '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds;
}

//userinfo接口调用
function userinfo() {
	mui.ajax(user_url + '/api/Silver/dealInfo', {
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))
			if(data.code == 10000) {
				var html = ""
				var hotShop = data.resp;
				for(var i = 0; i < hotShop.length; i++) {
					var status;
					if(hotShop[i].status=='购买'){
						status=1;
					}
					else{
						status=2;
					}
					html += '<li class="mui-table-view-cell advance_record_li" onclick="detailPage('+hotShop[i].id+','+status+')">'
					html += '<a class="mui-pull-left">'
					html += '白银'+hotShop[i].status+''
					html += '<p>'+hotShop[i].createtime+'</p>'
					html += '</a>'
					if(status==1){
						html += '<span class="mui-pull-right" style="color:#e60012;">+<i>'+hotShop[i].sum_price+'</i></span>'
					}
					else{
						html += '<span class="mui-pull-right" style="color:#23cd23;">-<i>'+hotShop[i].sum_price+'</i></span>'
					}
					html += '<span class="mui-icon mui-icon-forward account_icon"></span>'
					html += '</li>';
				}
				$(".advance_record_list").html(html);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});
}
var silberId;
function detailPage(idVal,txt) {
	console.log(txt);
	if(txt==1){
		mui.openWindow({
			url: '../my/yinDetail.html',
			extras: {
				silberId: idVal
			},
			createNew: true,
		});
	}
	else{
		mui.openWindow({
			url: '../my/yinDetail_success.html',
			extras: {
				silberId: idVal
			},
			createNew: true,
		});
	}
	
}

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
//		self = plus.webview.currentWebview();
		userinfo(); //用户接口方法
		plus.nativeUI.closeWaiting(); //关闭等待
		mask.close(); //关闭遮罩层
		// isPwd()
//		getSilverPrice()
			//页面刷新
		window.addEventListener('refresh_method', function(e) { //执行刷新
			location.reload();
		});
	});
}